/// <summary>
/// Generic Mono singleton.
/// </summary>
using UnityEngine;
namespace Miao
{
    public abstract class MonoSingleton<T> : MonoBehaviour where T : MonoSingleton<T>
    {

        private static T m_Instance = null;

        public static T Instance
        {
            get
            {
                if (m_Instance == null)
                {//因为确实有删除场景单例的需求，单例可以为空
                    m_Instance = GameObject.FindObjectOfType(typeof(T)) as T;
                }
                return m_Instance;
            }
        }

        private void Awake()
        {
            if (m_Instance == null)
            {
                m_Instance = this as T;
                m_Instance.Init();
            }
        }

        public virtual void Init() { }


        private void OnApplicationQuit()
        {
            m_Instance = null;
        }
    }
}